package 洛谷;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class A减B数对 {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sp = br.readLine().split(" ");
		int n = Integer.parseInt(sp[0]);
		int c = Integer.parseInt(sp[1]);
		int[] a = new int[n];
		String[] sp2 = br.readLine().split(" ");
		for (int i = 0; i < sp2.length; i++) {
			a[i] = Integer.parseInt(sp2[i]);
		}
		Arrays.sort(a);
		long cnt = 0;
		Map<Integer, Integer> map = new HashMap<>();
		// 先记录每种元素出现的次数
		for (int i = 0; i < a.length; i++) {
			map.put(a[i], map.getOrDefault(a[i], 0) + 1);
		}
		//A=B+C
		for (int i = a.length - 1; i >= 0; i--) {
			int index = a[i] + c;
			if (map.containsKey(index)) {
				cnt += map.get(index);
			}
		}
		System.out.println(cnt);
	}
}
